<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="关键字：">
          <el-input v-model="listPram.keyword" placeholder="客服电话/客服名称" clearable class="selWidth"/>
        </el-form-item>
        <el-form-item label="地区:" prop="areaId">
          <el-cascader class="col"
                       placeholder="可输入地区名称进行搜索"
                       v-model="value"
                       :options="options"
                       clearable
                       :props="{ expandTrigger: 'hover' }"
                       filterable
                       @change="handleChange"></el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-form-item class="el-form-item-align-right">
          <el-button icon="el-icon-circle-plus" size="mini" type="primary" @click="openEdit()"
                     v-has-permi="['admin:exclusiveService:save']">添加
          </el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.customerServiceModelList"
                :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}"
                border size="mini">
        <el-table-column label="ID" prop="id" min-width="35"></el-table-column>
        <el-table-column label="姓名" min-width="130" prop="name"/>
        <el-table-column label="联系方式" min-width="80" prop="phone"/>
        <el-table-column label="邮箱" min-width="80" prop="email"/>
        <el-table-column label="昵称" min-width="80" prop="nickname"/>
        <el-table-column label="管辖数量上限" min-width="80" prop="maxNum"/>
        <el-table-column label="所管辖地区" min-width="100" prop="areaText"/>
        <el-table-column align="center" fixed="right" label="操作" min-width="250">
          <template slot-scope="scope">
            <el-button v-has-permi="['admin:exclusiveService:list']" icon="el-icon-document-remove" size="mini"
                       type="warning"
                       @click="openEditList(scope.row.id,scope.row)">辖区会员
            </el-button>
            <el-button v-has-permi="['admin:exclusiveService:save']" icon="el-icon-edit" size="mini" type="primary"
                       @click="openEdit(scope.row.id)">编辑
            </el-button>
            <el-button v-has-permi="['admin:exclusiveService:delete']" icon="el-icon-delete" size="mini" type="danger"
                       @click="handlerDelete(scope.row.id)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[20,40,60,80,100]"
          :total="listData.count"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
        :close-on-click-modal="false"
        :title="editDialog.id? '编辑':'新增'"
        :visible.sync="editDialog.show"
        destroy-on-close
        top="60px"
        width="800px">
      <edit
          v-if="editDialog.show"
          :id="editDialog.id"
          :businessTypeList="editDialog.businessTypeList"
          ref="editForm"
          @hideEditDialog="hideEditDialog"
      />
    </el-dialog>
    <el-dialog
        :close-on-click-modal="false"
        title="会员列表"
        :visible.sync="editDialogList.show"
        destroy-on-close
        top="80px"
        width="1200px">
      <jurisdiction
          v-if="editDialogList.show"
          :id="editDialogList.id"
          :edit-data="editDialogList.editDate"
          ref="editForm"
          @editListDialog="editListDialog"
      />
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit.vue'
import {deleteRow, list, optionsList, updateStatus} from "@/api/exclusiveService";
import {checkPermi} from "@/utils/permission";
import jurisdiction from "@/views/operate/exclusiveService/jurisdiction/index.vue";

export default {
  components: {edit, jurisdiction},
  data() {
    return {
      listData: {customerServiceModelList: [], count: 0},
      listPram: {
        page: 1,
        limit: 20,
        keyword: '',
        areaId: ''
      },
      editDialog: {
        show: false,
        id: null,
        businessTypeList: [],
      },
      editDialogList: {
        show: false,
        id: null,
        editDate: {},
        pid: null
      },
      grant: {
        show: false,
        id: null,
        editDate: {},
        pid: null
      },
      tableLoading: false,
      statusList: [{id: 1, data: '营业中'}, {id: 2, data: '未营业'}],
      imageUrl: '',
      value: [],
      options: [{
        value: '',
        label: '',
        children: [{
          value: '',
          label: '',
          children: [{
            value: '',
            label: ''
          }]
        }]
      }],
    }
  },
  mounted() {
    this.imageUrl = process.env.VUE_APP_IMAGE_URL
    this.getList()
    this.getOptions()
  },
  methods: {
    handleChange(value) {
      this.listPram.areaId = value[2]
    },
    getOptions() {
      optionsList().then(res => {
        this.options = res
      })
    },
    checkPermi,
    getList() {
      this.tableLoading = true
      list(this.listPram).then(res => {
        this.listData = res;
      }).finally(() => {
      })
      this.tableLoading = false;
    },
    openEdit(id = null) {
      this.editDialog.id = id;
      this.editDialog.show = true
    },
    openEditList(id = null, editDate) {
      this.editDialogList.id = id;
      this.editDialogList.show = true
      this.editDialogList.editDate = editDate
    },
    openGrant(id = null, editDate) {
      this.grant.id = id;
      this.grant.show = true
      this.grant.editDate = editDate
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading = this.$loading({text: '删除中', background: 'rgba(255,255,255,.5)'})
        deleteRow(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(() => {
          loading.close()
        })
      })
    },
    hideGrantDialog() {
      this.grant.show = false
      this.getList()
    },
    hideEditDialog() {
      this.editDialog.show = false
      this.getList()
    },
    editListDialog() {
      this.editDialogList.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    handleStatusChange(status, id) {
      const loading = this.$loading({text: '更新中', background: 'rgba(255,255,255,.5)'})
      updateStatus(id, status).then(() => {
        this.$message.success('更新状态成功')
        this.getList()
      }).finally(() => {
        loading.close()
      })
    },
    resetQuery() {
      this.listPram.keyword = '';
      this.listPram.areaId = '';
      this.value = '';
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">

</style>

<style scoped>

</style>
